package com.yunsom.testdemo.design.flyweight;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author Xbao
 * @description
 * @date 2022/6/21 15:45
 */
public class ShapeFactory {

  private static final Map<String,Circle> circleMap = new HashMap<>();

  public static Shape getCircle(String color){
    Circle circle = circleMap.get(color);

    if(Objects.isNull(circle)){
      circle = new Circle(color);
      circleMap.put(color, circle);
      System.out.println("--");
      System.out.printf("create circle of color :%s", color);
      System.out.println("--");
    }
    return circle;
  }

}
